home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-02-27 | 16.5 KB | 572 lines | [TEXT/CWIE] |
- /* SK8 © 1997 Apple Computer, Inc.
- This code is protected under the current SK8 License
- See http://sk8.research.apple.com/ for more information
- Apple Research Laboratories
- */
-
- import java.applet.Applet;
- import java.awt.*;
- import java.util.Random;
-
- // Here we store all the default instances of objects we want around.
- // Note that you can remove the static instances that you do not need
- // in order to improve startup time and memory footprint.
-
- class sk8 {
-
- //----------------------------------------
- //Object Instances
- //----------------------------------------
- private static Random random_generator = new Random();
-
-
-
- //-----------------------------------------------------------------------------------
- // BEGIN GRAPHIC RELATED GLOBALS
- // Comment these out if you wish to have a non graphical version of this code
- //--------------------------------
- //GLOBALS FILLED IN AT STARTUP
- public static Applet currentApplet = null;
- public static Event latestEvent = null;
-
- //Devices
- public static Mouse mouse = new Mouse();
-
- // The Stage
- public static stage stage = null;
-
- //RGBColors
- public static rgbcolor white = new rgbcolor(255, 255, 255);
- public static rgbcolor graytone95 = new rgbcolor(243, 243, 243);
- public static rgbcolor graytone90 = new rgbcolor(230, 230, 230);
- public static rgbcolor graytone85 = new rgbcolor(218, 218, 218);
- public static rgbcolor graytone80 = new rgbcolor(205, 205, 205);
- public static rgbcolor graytone75 = new rgbcolor(192, 192, 192);
- public static rgbcolor graytone70 = new rgbcolor(179, 179, 179);
- public static rgbcolor graytone65 = new rgbcolor(166, 166, 166);
- public static rgbcolor graytone60 = new rgbcolor(154, 154, 154);
- public static rgbcolor graytone55 = new rgbcolor(141, 141, 141);
- public static rgbcolor graytone50 = new rgbcolor(128, 128, 128);
- public static rgbcolor graytone45 = new rgbcolor(115, 115, 115);
- public static rgbcolor graytone40 = new rgbcolor(102, 102, 102);
- public static rgbcolor graytone35 = new rgbcolor(90, 90, 90);
- public static rgbcolor graytone30 = new rgbcolor(77, 77, 77);
- public static rgbcolor graytone25 = new rgbcolor(64, 64, 64);
- public static rgbcolor graytone20 = new rgbcolor(51, 51, 51);
- public static rgbcolor graytone15 = new rgbcolor(38, 38, 38);
- public static rgbcolor graytone10 = new rgbcolor(26, 26, 26);
- public static rgbcolor graytone05 = new rgbcolor(13, 13, 13);
- public static rgbcolor black = new rgbcolor(0, 0, 0);
- public static rgbcolor darkgray = new rgbcolor(64, 64, 64);
- public static rgbcolor gray = new rgbcolor(128, 128, 128);
- public static rgbcolor lightgray = new rgbcolor(195, 195, 195);
- public static rgbcolor lightbrown = new rgbcolor(223, 131, 34);
- public static rgbcolor brown = new rgbcolor(180, 105, 27);
- public static rgbcolor darkbrown = new rgbcolor(100, 59, 16);
- public static rgbcolor lightpurple = new rgbcolor(125, 0, 255);
- public static rgbcolor purple = new rgbcolor(70, 0, 164);
- public static rgbcolor darkpurple = new rgbcolor(57, 0, 133);
- public static rgbcolor lightblue = new rgbcolor(0, 172, 255);
- public static rgbcolor blue = new rgbcolor(0, 0, 215);
- public static rgbcolor darkblue = new rgbcolor(0, 0, 128);
- public static rgbcolor lightgreen = new rgbcolor(59, 215, 86);
- public static rgbcolor green = new rgbcolor(31, 184, 20);
- public static rgbcolor darkgreen = new rgbcolor(0, 102, 17);
- public static rgbcolor lightyellow = new rgbcolor(255, 255, 128);
- public static rgbcolor yellow = new rgbcolor(255, 255, 0);
- public static rgbcolor darkyellow = new rgbcolor(223, 223, 0);
- public static rgbcolor lightorange = new rgbcolor(255, 172, 0);
- public static rgbcolor orange = new rgbcolor(255, 128, 0);
- public static rgbcolor darkorange = new rgbcolor(195, 98, 0);
- public static rgbcolor lightred = new rgbcolor(255, 128, 128);
- public static rgbcolor red = new rgbcolor(255, 0, 0);
- public static rgbcolor darkred = new rgbcolor(128, 0, 0);
- public static rgbcolor cyan = new rgbcolor(0, 255, 255);
- public static rgbcolor tan = new rgbcolor(145, 113, 59);
- public static rgbcolor pink = new rgbcolor(255, 8, 128);
- public static rgbcolor vomit = new rgbcolor(207, 94, 66);
-
- //Gradients
- public static gradient bluetunnel = new gradient(0, 128, 255, 0, 0, 62, gradient.rect);
- public static gradient blacktored = new gradient(0, 0, 0, 255, 0, 0, gradient.horizontal);
- public static gradient starburst = new gradient(0, 0, 0, 255, 0, 0, gradient.oval);
- public static gradient metal2 = new gradient(234, 234, 234, 78, 78, 78, gradient.vertical);
- public static gradient metal1 = new gradient(78, 78, 78, 234, 234, 234, gradient.vertical);
- public static gradient sunset = new gradient(78, 0, 117, 255, 128, 128, gradient.vertical);
- public static gradient blacktowhite = new gradient(0,0,0,255,255,255,gradient.horizontal);
-
- //Bevels
- public static bevelrenderer uirectangleinbevel = new bevelrenderer(black, darkgray, gray, gray);
- public static bevelrenderer uirectangleoutbevel = new bevelrenderer(gray, gray, black, darkgray);
-
- //transparent FIX ME
- public static rgbcolor transparent = sk8.white;
-
-
-
- //--------------------------------
- // END GRAPHIC RELATED GLOBALS
- //-----------------------------------------------------------------------------------
-
- //symbol
- public static symbol symbol = sk8.quote("SYMBOL");
-
- //Constants
- public static double pi = Math.PI;
- public static double e = Math.E;
-
- //----------------------------------------
- //Project Functions
- //----------------------------------------
-
- public static Object sk8new (Object obj) {
- try {
- try {
- Class objclass = obj.getClass();
- Object newobject = objclass.newInstance();
- return newobject;
- } catch (InstantiationException e) {
- return null;
- }
- } catch (IllegalAccessException e) {
- return null;
- }
- }
-
-
- //SendToLog
- public static void sendtolog (Object obj) {
- System.out.println(obj);
- }
- public static void sendtolog (int t) {
- System.out.println(t);
- }
-
- //Random Numbers
- public static int random(int limit) {
- if (limit == 0) {
- return 0;
- } else {
- int res = (random_generator.nextInt() % limit);
- res = Math.abs(res);
- return res;
- }
- }
- public static float random(float limit) {
- if (limit == 0) {
- return 0;
- } else {
- float res = (random_generator.nextFloat() % limit);
- return res;
- }
- }
-
-
- //Symbols
- public static symbol quote (String nameForSym) { //sk8 function wrapper for symbol static method getsymbol
- return symbol.getsymbol(nameForSym.toUpperCase());
- }
-
-
- public static list keys (table t) {
- return t.keys();
- }
-
- //Lists
- public static list list () {
- return new list();
- }
-
- public static list list (Object obj1) {
- list ll = new list();
- ll.push(obj1);
- return ll;
- }
- public static list list (Object obj1, Object obj2) {
- list ll = new list();
- ll.push(obj2);
- ll.push(obj1);
- return ll;
- }
- public static list list (Object obj1, Object obj2, Object obj3) {
- list ll = new list();
- ll.push(obj3);
- ll.push(obj2);
- ll.push(obj1);
- return ll;
- }
- public static list list (Object obj1, Object obj2, Object obj3, Object obj4) {
- list ll = new list();
- ll.push(obj4);
- ll.push(obj3);
- ll.push(obj2);
- ll.push(obj1);
- return ll;
- }
- public static list list (Object obj1, Object obj2, Object obj3, Object obj4, Object obj5) {
- list ll = new list();
- ll.push(obj5);
- ll.push(obj4);
- ll.push(obj3);
- ll.push(obj2);
- ll.push(obj1);
- return ll;
- }
- public static list list (Object obj1, Object obj2, Object obj3, Object obj4, Object obj5, Object obj6) {
- list ll = new list();
- ll.push(obj6);
- ll.push(obj5);
- ll.push(obj4);
- ll.push(obj3);
- ll.push(obj2);
- ll.push(obj1);
- return ll;
- }
- public static list list (Object obj1, Object obj2, Object obj3, Object obj4, Object obj5, Object obj6, Object obj7) {
- list ll = new list();
- ll.push(obj7);
- ll.push(obj6);
- ll.push(obj5);
- ll.push(obj4);
- ll.push(obj3);
- ll.push(obj2);
- ll.push(obj1);
- return ll;
- }
-
- public static list list (int obj1) {
- list ll = new list();
- ll.push(new Integer(obj1));
- return ll;
- }
- public static list list (int obj1, int obj2) {
- list ll = new list();
- ll.push(new Integer(obj2));
- ll.push(new Integer(obj1));
- return ll;
- }
- public static list list (int obj1, int obj2, int obj3) {
- list ll = new list();
- ll.push(new Integer(obj3));
- ll.push(new Integer(obj2));
- ll.push(new Integer(obj1));
- return ll;
- }
- public static list list (int obj1, int obj2, int obj3, int obj4) {
- list ll = new list();
- ll.push(new Integer(obj4));
- ll.push(new Integer(obj3));
- ll.push(new Integer(obj2));
- ll.push(new Integer(obj1));
- return ll;
- }
- public static list list (float obj1) {
- list ll = new list();
- ll.push(new Float(obj1));
- return ll;
- }
- public static list list (float obj1, float obj2) {
- list ll = new list();
- ll.push(new Float(obj2));
- ll.push(new Float(obj1));
- return ll;
- }
- public static list list (float obj1, float obj2, float obj3) {
- list ll = new list();
- ll.push(new Float(obj3));
- ll.push(new Float(obj2));
- ll.push(new Float(obj1));
- return ll;
- }
- public static list list (float obj1, float obj2, float obj3, float obj4) {
- list ll = new list();
- ll.push(new Float(obj4));
- ll.push(new Float(obj3));
- ll.push(new Float(obj2));
- ll.push(new Float(obj1));
- return ll;
- }
-
-
- //To make a list of red, green and blue, you make a static array of these guys
- //and call the sk8.list function. e.g.:
- //Object tempvar[] = {sk8.red, sk8.green, sk8.blue};
- //sk8.list(tempvar);
-
- public static list list (Object elements[]) {
- list ll = new list();
- for (int i = elements.length - 1; i >= 0; i--) {
- ll.push(elements[i]);
- }
- return ll;
- }
-
- public static list list (int elements[]) {
- list ll = new list();
- for (int i = elements.length - 1; i >= 0; i--) {
- ll.push(new Integer(elements[i]));
- }
- return ll;
- }
- public static list list (float elements[]) {
- list ll = new list();
- for (int i = elements.length - 1; i >= 0; i--) {
- ll.push(new Float(elements[i]));
- }
- return ll;
- }
-
-
- //-----------------------------------------------------------------------------------
- //Coercion
- //-----------------------------------------------------------------------------------
-
- public static symbol asa (String str, symbol s) {
- return sk8.quote(str);
- }
-
- public static String asa (Object obj, String s) {
- return obj.toString();
- }
-
-
- //-----------------------------------------------------------------------------------
- //Collection Front End
- //-----------------------------------------------------------------------------------
-
- public static void insertinfront (Object it, collection ll) {
- ll.push(it);
- }
- public static void insertatend (Object it, collection ll) {
- ll.pushend(it);
- }
- public static void insertinfront (int it, collection ll) {
- ll.push(new Integer(it));
- }
- public static void insertatend (int it, collection ll) {
- ll.pushend(new Integer(it));
- }
- public static void insertinfront (float it, collection ll) {
- ll.push(new Float(it));
- }
- public static void insertatend (float it, collection ll) {
- ll.pushend(new Float(it));
- }
- public static void insertinfront (char it, collection ll) {
- ll.push(new Character(it));
- }
- public static void insertatend (char it, collection ll) {
- ll.pushend(new Character(it));
- }
-
- public static String insertinfront (String it, String ll) {
- return it.concat(ll);
- }
- public static String insertatend (String it, String ll) {
- return ll.concat(it);
- }
-
- public static collection reverse (list ll) {
- return ll.reverse();
- }
-
- public static String reverse (String ll) {
- StringBuffer s1 = new StringBuffer(ll);
- return s1.reverse().toString();
- }
-
- public static int length (collection ll) {
- return ll.length();
- }
-
- public static int length (String ll) {
- return ll.length();
- }
-
- public static boolean contains (collection ll, Object obj) {
- return ll.contains(obj);
- }
-
- public static boolean contains (collection ll, char ch) {
- Character c = new Character(ch);
- return ll.contains((Object)c);
- }
-
- public static list concatenate (list ll1, list ll2) {
- return list.concatenate(ll1,ll2);
- }
- public static list concatenate (list ll1, Object e) {
- ll1.pushend(e);
- return ll1;
- }
- public static String concatenate (String str1, String str2) {
- return (str1 + str2);
- }
-
-
- public static list collectionsubsequence(collection c, int start, int end) {
- return c.range(start, end);
- }
-
- public static String collectionsubsequence(String c, int start, int end) {
- return c.substring(start - 1, end);
- }
-
-
- //-----------------------------------------------------------------------------------
- //Math functions
- //-----------------------------------------------------------------------------------
-
- public static int max (int i1, int i2) {
- return Math.max(i1, i2);
- }
- public static float max (float i1, float i2) {
- return Math.max(i1, i2);
- }
- public static double max (double i1, double i2) {
- return Math.max(i1, i2);
- }
- public static long max (long i1, long i2) {
- return Math.max(i1, i2);
- }
- public static int min (int i1, int i2) {
- return Math.min(i1, i2);
- }
- public static float min (float i1, float i2) {
- return Math.min(i1, i2);
- }
- public static double min (double i1, double i2) {
- return Math.min(i1, i2);
- }
- public static long min (long i1, long i2) {
- return Math.min(i1, i2);
- }
- public static int abs (int i1) {
- return Math.abs(i1);
- }
- public static float abs (float i1) {
- return Math.abs(i1);
- }
- public static double abs (double i1) {
- return Math.abs(i1);
- }
- public static long abs (long i1) {
- return Math.abs(i1);
- }
- public static double floor (double i1) {
- return Math.floor(i1);
- }
- public static double ceiling (double i1) {
- return Math.ceil(i1);
- }
- public static double sqrt (double i1) {
- return Math.sqrt(i1);
- }
- public static double log (double i1) {
- return Math.log(i1);
- }
- public static double exp (double i1) {
- return Math.exp(i1);
- }
- public static int round (float i1) {
- return Math.round(i1);
- }
-
-
- //-----------------------------------------------------------------------------------
- // BEGIN GRAPHIC RELATED FUNCTIONS
- // Comment these out if you wish to have a non graphical version of this code
- //--------------------------------
-
- //-----------------------------------------------------------------------------------
- // Event Related Functions
- //-----------------------------------------------------------------------------------
- public static actor eventactor () {
- return sk8.stage.eventactorVar;
- }
-
- public static actor eventwindow() {
- return sk8.stage.eventwindowVar;
- }
-
- public static long eventtime() {
- return sk8.stage.eventtimeVar;
- }
-
- public static int eventh() {
- return sk8.stage.eventhVar;
- }
-
- public static int eventv() {
- return sk8.stage.eventvVar;
- }
-
- //Modifier keys
-
- public static boolean shiftkeydown() {
- return sk8.stage.shiftkeydownVar;
- }
-
- public static boolean controlkeydown() {
- return sk8.stage.controlkeydownVar;
- }
-
- public static boolean commandkeydown() {
- return sk8.stage.commandkeydownVar;
- }
-
- public static boolean optionkeydown() {
- return sk8.stage.optionkeydownVar;
- }
-
- //actorathvcoordinations
- //IMPLEMENT ME FIX ME
- public static actor actorathvcoordinates(int h, int v) {
- return null;
- }
-
- //-----------------------------------------------------------------------------------
- // XOR Drawing Functions
- // *** Stubs for now. Is this available in Java?
- //-----------------------------------------------------------------------------------
- public static void zoomrect(int l1, int t1, int r1, int b1,
- int l2, int t2, int r2, int b2) {
-
- //ZOOM!!! :)
- }
- public static void drawxorframe(int l1, int t1, int r1, int b1) {
- //Whoosh!!
- }
-
-
- //-----------------------------------------------------------------------------------
- // Interactions with the user...
- //-----------------------------------------------------------------------------------
-
- public static void messagetouser (String message) {
- /* @@@@@@FIX ME Need to figure out how to get frame for this.
- messagedialog thedialog = new messagedialog(FRAME GOES HERE, message);
- list monitorcenter = sk8.mainmonitorcenter();
- Dimension mysize = thedialog.size();
- thedialog.move(monitorcenter.nthint(1) - mysize.width/2,
- monitorcenter.nthint(2) - mysize.height/2);
- thedialog.show();
- */
- }
-
- //-----------------------------------------------------------------------------------
- // system info...
- //-----------------------------------------------------------------------------------
-
- public static list mainmonitorcenter () {
- Rectangle bounds = sk8.stage.boundsrect();
- return sk8.list(bounds.x + bounds.width/2, bounds.y + bounds.height/2);
- }
-
- //--------------------------------
- // END GRAPHIC RELATED FUNCTIONS
- //-----------------------------------------------------------------------------------
-
-
-
- }